import requests
from baseTools.myLogger import logger
from config import *

class BaseAPI():

    def get_token(self):
        logger.info("获取token信息")
        my_params = {
            "corpid": corpid,
            "corpsecret": corpsecret
        }
        rep = requests.request(method='get', url=tokoen_url, params=my_params)
        self.token = rep.json()['access_token']
        logger.info("token获取成功，token值为：{}".format(self.token))

    def my_get(self, url, data):
        logger.info("执行get请求，请求url：{}，请求数据为：{}".format(url, data))
        data['access_token'] = self.token
        rep = requests.request(method='get', url=url, params=data)
        return rep.json()

    def my_post(self, url, data):
        logger.info("执行post请求，请求url：{}，请求数据为：{}".format(url, data))
        param = {'access_token': self.token}
        rep = requests.request(method='post', url=url, params=param, json=data)
        return rep.json()
